package cn.initcap.algorithm.sort.heap;

import cn.initcap.algorithm.sort.SortTestHelper;

/**
 * 使用最小索引堆进行堆排序, 来验证我们的最大索引堆的正确性
 *
 * @author initcap
 * @date Created in 2018/6/22 PM6:13.
 */
public class IndexMinHeapSort {

    private IndexMinHeapSort() {
    }

    public static void sort(Comparable[] arr) {

        int n = arr.length;

        IndexMinHeap<Comparable> indexMinHeap = new IndexMinHeap<Comparable>(n);
        for (int i = 0; i < n; i++) {
            indexMinHeap.insert(i, arr[i]);
        }

        for (int i = 0; i < n; i++) {
            arr[i] = indexMinHeap.extractMin();
        }
    }

    public static void main(String[] args) {

        int n = 1000000;
        Integer[] arr = SortTestHelper.generateRandomArray(n, 0, 100000);
        SortTestHelper.testSort("cn.initcap.algorithm.sort.heap.IndexMinHeapSort", arr);
    }
}
